package a66weding.com.jiehuntong.pager;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.io.InputStream;
import java.util.ArrayList;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.activity.ToolsGiftsActivity;
import a66weding.com.jiehuntong.activity.Tools_MaramissActivity;
import a66weding.com.jiehuntong.adapter.Tools_ExpandableListViewAdapter;
import a66weding.com.jiehuntong.common.utils.CUtils;

/**
 * @version :
 * @creator : AxDu
 * @create-time : 2016/6/2
 * @description :
 */
public class ToolsPager_Task_Addtask extends BasePager implements View.OnClickListener {
    private Tools_MaramissActivity mTaskActivity;
    private View mContentview;
    private TextView tvLeft, tvCenter, tvRight;
    private ImageView addtask_iv;
    private ExpandableListView mExpandableListView;
    private Tools_ExpandableListViewAdapter mExpandableListViewAdapter;
    private Dialog cusDialog, typeDialog;
    private RelativeLayout cus_rl, custom_rl, rlFintime, rlTxtime;
    private View typeView;

    public ToolsPager_Task_Addtask(Activity activity) {
        super(activity);

    }


    @Override
    protected View getView() {
        mTaskActivity= (Tools_MaramissActivity) mActivity;

        mContentview = View.inflate(mTaskActivity, R.layout.pager_tools_task_adtask,null);
        tvLeft = (TextView) mContentview.findViewById(R.id.headleft_title_tv);
        tvCenter = (TextView) mContentview.findViewById(R.id.headcenter_title_tv);
        tvRight = (TextView) mContentview.findViewById(R.id.headright_title_tv);

        mExpandableListView = (ExpandableListView) mContentview.findViewById(R.id.expandableListView);
        mExpandableListViewAdapter = new Tools_ExpandableListViewAdapter(mActivity);
        mExpandableListView.setAdapter(mExpandableListViewAdapter);
        mExpandableListView.expandGroup(0);

        tvLeft.setText("工具");
        tvCenter.setText("添加任务");
        tvRight.setText("自定义任务");

        tvLeft.setOnClickListener(this);
        tvRight.setOnClickListener(this);

        mExpandableListView
                .setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
                    @Override
                    public boolean onGroupClick(ExpandableListView parent,
                                                View v, int groupPosition, long id) {
                        return false;
                    }
                });
        mExpandableListView
                .setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                    @Override
                    public boolean onChildClick(ExpandableListView parent,
                                                View v, int groupPosition, int childPosition,
                                                long id) {

                        return false;
                    }
                });

        return mContentview;
    }


    @Override
    public void initData() {



    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
                case R.id.btn_tools_dayplan_editcommit:

                break;
                case R.id.iv_addgift_fromphone:

                break;
            case R.id.headright_title_tv:
                showCustomtask();
                break;


        }
    }


    /**
     * 添加任务类型
     */
    private void showTasktype() {
        typeView = View.inflate(mActivity, R.layout.tools_dialog_customtype, null);
        typeDialog = new Dialog(mActivity, R.style.transparentFrameWindowStyle);
        typeDialog.setContentView(typeView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Window window = typeDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = window.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.MATCH_PARENT;
        // 设置显示位置
        typeDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        typeDialog.setCanceledOnTouchOutside(true);
        typeDialog.show();
    }



    /**
     * 添加任务
     */
    private void showCustomtask() {
        cusDialog = new Dialog(mActivity, R.style.dialog);
        cusDialog.setContentView(R.layout.tools_dialog_customtask);
        rlFintime = (RelativeLayout) cusDialog.findViewById(R.id.custom_fintime_rl);
        rlTxtime = (RelativeLayout) cusDialog.findViewById(R.id.custom_txtime_rl);
        cus_rl = (RelativeLayout) cusDialog.findViewById(R.id.customtask_rl);
        custom_rl = (RelativeLayout) cusDialog.findViewById(R.id.customtask_custom_rl);
        rlFintime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CUtils.showToast("完成时间");
            }
        });
        rlTxtime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CUtils.showToast("提醒时间");
            }
        });
        custom_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CUtils.showToast("hehe");
                showTasktype();
            }
        });

        Window window = cusDialog.getWindow();
        // 可以在此设置显示动画
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = window.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        cusDialog.onWindowAttributesChanged(wl);
        cusDialog.show();
    }









}
